{
LANG : PASCAL
PROB : camelot
}

program CAMELOT;
const
  fi = 'camelot.in';
  fo = 'camelot.out';
  dx : array[1..8] of integer = (-2, -2, -1, 1, 2, 2, 1, -1);
  dy : array[1..8] of integer = (-1, 1, 2, 2, 1, -1, -2, -2);
  hx : array[1..9] of integer = (0, -1, -1, 0, 1, 1, 1, 0, -1);
  hy : array[1..9] of integer = (0, 0, 1, 1, 1, 0, -1, -1, -1);
  maxr = 40;
  maxc = 26;
type
  table = array[1..maxr, 1..maxc] of integer;
  point = record
            x, y : shortint;
          end;
var
  d : table;
  k : array[1..9] of table;
  pking, king : point;
  pknight : array[1..maxr*maxc] of point;
  m, n, s, best : longint;

procedure doc(var p : point);
var
  c : char;
begin
  if not seekeof then read(c);
  p.y := ord(c) - 64;
  if not seekeof then read(p.x);
end;

procedure inp;
begin
  readln(m, n);
  s := 0;
  doc(king);
  if seekeoln then readln;
  while not seekeof do
  begin
    inc(s);
    doc(pknight[s]);
    if seekeoln then readln;
  end;
end;

function inside(p : point) : boolean;
begin
  inside := (1 <= p.x) and (p.x <= m) and (1 <= p.y) and (p.y <= n);
end;

procedure BFS(gx, gy : integer; var a : table);
var
  q : array[1..maxr*maxc] of point;
  u, v : point;
  i, l, r : longint;
begin
  l := 1;
  r := 1;
  q[1].x := gx;
  q[1].y := gy;
  fillchar(a, sizeof(a), $30);
  a[gx, gy] := 0;
  while l <= r do
  begin
    u := q[l];
    inc(l);
    for i := 1 to 8 do
    begin
      v.x := u.x + dx[i];
      v.y := u.y + dy[i];
      if inside(v) and (a[v.x, v.y] > a[u.x, u.y] + 1) then
      begin
        a[v.x, v.y] := a[u.x, u.y] + 1;
        inc(r);
        q[r] := v;
      end;
    end;
  end;
end;

procedure init;
var
  e : integer;
begin
  best := maxlongint;
  for e := 1 to 9 do
  begin
    pking.x := king.x + hx[e];
    pking.y := king.y + hy[e];
    if not inside(pking) then continue;
    BFS(pking.x, pking.y, k[e]);
  end;
end;

procedure process;
var
  i, e, gx, gy : integer;
  sum, temp : longint;
begin
  for gx := 1 to m do
    for gy := 1 to n do
    begin
      BFS(gx, gy, d);
      for e := 1 to 9 do
      begin
        pking.x := king.x + hx[e];
        pking.y := king.y + hy[e];
        if not inside(pking) then continue;
        sum := 0;
        if e > 1 then sum := 1;

        inc(sum, abs(pking.x - gx) + abs(pking.y - gy));
        for i := 1 to s do
          with pknight[i] do inc(sum, d[x, y]);
        if best > sum then best := sum;
        dec(sum, abs(pking.x - gx) + abs(pking.y - gy));

        for i := 1 to s do
          with pknight[i] do
          begin
            temp := sum-d[x, y]+k[e, x, y]+d[pking.x, pking.y];
            if best > temp then best := temp;
          end;
      end;
    end;
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  inp;
  init;
  process;
  writeln(best);
  close(output);
  close(input);
end.